package com.lanou3g.ptp.api.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lanou3g.ptp.entity.TempRecord;
import com.lanou3g.ptp.entity.TempSignIn;
import com.lanou3g.ptp.task.service.TempSignService;
import com.lanou3g.ptp.utils.PtpResult;
import com.lanou3g.ptp.utils.PtpResultUtils;
import com.lanou3g.ptp.vo.RecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("临时查岗相关接口")
@RestController
@Slf4j
public class TempSignController {

    @Reference
    private TempSignService tempSignService;

    @ApiOperation("老师创建临时查岗事件")
    @PostMapping("/record/temp")
    public PtpResult createCheckRecord(@RequestBody RecordVO record) {
        boolean success = this.tempSignService.addRecord(record);
        if (success) {
            return PtpResultUtils.ok();
        }else {
            return PtpResultUtils.error(500);
        }
    }

    @ApiOperation("获取某个任务下的临时查岗列表")
    @GetMapping("/task/{taskId}/record/temp")
    public PtpResult records(@PathVariable Long taskId) {
        List<TempRecord> tempRecords = this.tempSignService.findRecordsByTaskId(taskId);
        return PtpResultUtils.ok(tempRecords);
    }

    @ApiOperation("获取某次临时打卡的学生打卡详情")
    @GetMapping("/record/{recordId}/details")
    public PtpResult tempSignInDetails(@PathVariable Long recordId) {
        List<TempSignIn> details = this.tempSignService.tempSignInDetails(recordId);
        return PtpResultUtils.ok(details);
    }

}
